package at.fhj.mobsecdev.cookit.webrequests;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;

public class HashUtils {
	
	/**
	 * Hashes the credentials with SHA1 (to securely send them to the web service)
	 * @param username username to hash
	 * @param passwordHash passwordHash to hash
	 * @param timeStamp timestamp to hash
	 * @return hashed value
	 */
	public static String hashCredentials(String username, String passwordHash, String timeStamp)
	{
		return new String(Hex.encodeHex(DigestUtils.sha1(username+passwordHash+timeStamp)));
	}
	
	/**
	 * Hashes a password with SHA1 (to securely send it to the web service)
	 * @param plaintextPassword password to hash
	 * @return hashed password
	 */
	public static String hashPlaintextPassword(String plaintextPassword)
	{
		return new String(Hex.encodeHex(DigestUtils.sha1(plaintextPassword)));
	}
}
